/*
 * Copyright (c) 2022  by Junzhao
 * THIS FILE IS PART OF JAVA-Data-Structures-and-Algorithms PROJECT
 * All Rights Reserved.
 */

package 线性;

/**
 * @Description 线性查找
 * 遍历数组输出与元素相同的数组的下标 没有输出-1
 * @Author 俊昭
 * @Date 2022/5/2
 */
public class Linear {
    public static void search(int[] arr, int num) {
        boolean flag = true;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == num) {
                System.out.println(i);
                if (flag) {
                    flag = false;
                }
            }
        }
        if (flag) {
            System.out.println(- 1);
        }
    }
}
